package mx.netbrain.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import mx.netbrain.dao.OrganizationDao;
import mx.netbrain.dao.impl.OrganizationDaoImpl;
import mx.netbrain.model.Organization;
import mx.netbrain.model.Status;

public class OrganizationController {

	public static void saveOrganization(Organization organization, String name,
			String descripcion) {
		OrganizationDao organizationDao = new OrganizationDaoImpl();
		Status status = new Status();
		organization.setName(name);
		organization.setDescription(descripcion);
		status.setId(1);
		organization.setStatus(status);
		organization.setRegistro(new Date());
		organizationDao.save(organization);
	}

	public static void updateOrganization(Organization organization) {
		OrganizationDao organizationDao = new OrganizationDaoImpl();
		organizationDao.update(organization);
	}

	public static void deleteOrganization(Organization organization) {
		OrganizationDao organizationDao = new OrganizationDaoImpl();
		Status status = new Status();
		status.setId(2);
		organization.setStatus(status);
		organizationDao.delete(organization);
	}

	public static List<Organization> completeOrganization(String query,
			List<Organization> listOrganization) {
		List<Organization> suggestions = new ArrayList<Organization>();
		for (Organization o : listOrganization) {
			if (o.getName().startsWith(query))
				suggestions.add(o);
		}
		return suggestions;
	}

}
